package com.seed.core.configuration;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.seed.core.converter.ActionConverter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class MicroConfiguration extends IconConfiguration {
    protected String label;
    protected String comment;
    protected String component;
    protected LayoutConfiguration layout;
    protected Map<String, Object> componentProps;
    protected Map<String, HomeConfiguration> homes;
    protected Map<String, SeedConfiguration> seeds;
    protected Map<String, ActionConfiguration1> actions; // 独立行为
    protected String[] libs;

//    public Micro toMicro() {
//        Micro ret = new Micro();
//        if(this.seeds != null) {
//            Map<String, Seed> seeds = new HashMap<>();
//            for(Map.Entry<String, SeedConfiguration> entry: this.seeds.entrySet()) {
//                String seedName = entry.getKey();
//                Seed seed = entry.getValue().toSeed();
//                seed.setName(seedName);
//                seeds.put(seedName, seed);
//            }
//            ret.setSeeds(seeds);
//        }
//
//        if(this.actions != null) {
//            Map<String, Action> actions = new HashMap<>();
//            for(Map.Entry<String, ActionConfiguration> entry: this.actions.entrySet()) {
//                String actionName = entry.getKey();
//                Action action = entry.getValue().toAction();
//                action.setName(actionName);
//                actions.put(actionName, action);
//            }
//            ret.setActions(actions);
//        }
//
//        if(libs != null) ret.setLibs(List.of(libs));
//
//        return ret;
//    }

    public MicroConfiguration toFront() {
        MicroConfiguration ret = new MicroConfiguration();
        ret.setLabel(label);
        ret.setIcon(icon);
        ret.setSize(size);
        ret.setColor(color);
        ret.setHoverColor(hoverColor);
        ret.setComment(comment);
        ret.setComponent(component);
        ret.setLayout(layout);
        ret.setComponentProps(componentProps);
        ret.setHomes(homes);

        if(seeds != null) {
            Map<String, SeedConfiguration> frontSeeds = new HashMap<>();
            for(Map.Entry<String, SeedConfiguration> entry: seeds.entrySet()) {
                SeedConfiguration seed = entry.getValue();
                SeedConfiguration frontSeed = seed.toFront();
                frontSeeds.put(entry.getKey(), frontSeed);
            }
            ret.setSeeds(frontSeeds);
        }

        if(actions != null) {
            Map<String, ActionConfiguration1> frontActions = new HashMap<>();
            for(Map.Entry<String, ActionConfiguration1> entry: actions.entrySet()) {
                frontActions.put(entry.getKey(), ActionConverter.toFront(entry.getValue()));
            }
            ret.setActions(frontActions);
        }

        ret.setLibs(libs);

        return ret;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Map<String, SeedConfiguration> getSeeds() {
        return seeds;
    }

    public void setSeeds(Map<String, SeedConfiguration> seeds) {
        this.seeds = seeds;
    }

    public Map<String, ActionConfiguration1> getActions() {
        return actions;
    }

    public void setActions(Map<String, ActionConfiguration1> actions) {
        this.actions = actions;
    }

    public String getComponent() {
        return component;
    }

    public void setComponent(String component) {
        this.component = component;
    }

    public LayoutConfiguration getLayout() {
        return layout;
    }

    public void setLayout(LayoutConfiguration layout) {
        this.layout = layout;
    }

    public Map<String, Object> getComponentProps() {
        return componentProps;
    }

    public void setComponentProps(Map<String, Object> componentProps) {
        this.componentProps = componentProps;
    }

    public Map<String, HomeConfiguration> getHomes() {
        return homes;
    }

    public void setHomes(Map<String, HomeConfiguration> homes) {
        this.homes = homes;
    }

    public String[] getLibs() {
        return libs;
    }

    public void setLibs(String[] libs) {
        this.libs = libs;
    }
}
